package heven.holt.wan.android.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import heven.holt.wan.android.extensions.requestCoroutine
import heven.holt.wan.android.model.HotKeyModel
import heven.holt.wan.android.repository.WanConfigRepository
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
    private val wanConfigRepository: WanConfigRepository
) : ViewModel() {
    val hotKeys: MutableLiveData<List<HotKeyModel>?> = MutableLiveData()

    fun requestHotKeys() {
        viewModelScope.launch {
            val result: List<HotKeyModel>? = requestCoroutine {
                wanConfigRepository.getHotKey()
            }
            hotKeys.postValue(result)
        }
    }
}